pixbuf-engine: Improve ThemePixbuf clean up functions
authorEmmanuele Bassi <ebassi@gnome.org>
Mon, 18 Nov 2013 11:04:37 +0000 (11:04 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 23 Nov 2013 03:17:07 +0000 (22:17 -0500)
Make theme_pixbuf_destroy() NULL-safe like g_free(), and add a clear
function in the spirit of the g_clear_* family of functions.

https://bugzilla.gnome.org/show_bug.cgi?id=712536

modules/engines/pixbuf/pixbuf-render.c
modules/engines/pixbuf/pixbuf.h

index 6fb93bc495d8916cd105eb19c2f09d9cbf6c0e20..1b2fd991c8a066ac367360da04b64a724b8534b0 100644 (file)
@@ -492,8 +492,25 @@ theme_pixbuf_new (void)
 void
 theme_pixbuf_destroy (ThemePixbuf *theme_pb)
 {
-  theme_pixbuf_set_filename (theme_pb, NULL);
-  g_free (theme_pb);
+  if (G_LIKELY (theme_pb))
+    {
+      theme_pixbuf_set_filename (theme_pb, NULL);
+      g_free (theme_pb);
+    }
+}
+
+void
+theme_clear_pixbuf (ThemePixbuf **theme_pb)
+{
+#if GLIB_CHECK_VERSION (2, 34, 0)
+  g_clear_pointer (theme_pb, theme_pixbuf_destroy);
+#else
+  if (*theme_pb)
+    {
+      theme_pixbuf_destroy (*theme_pb);
+      *theme_pb = NULL;
+    }
+#endif
 }
 
 void         
index c844421f383b6944533f4b55240afe0ac039a59f..03cbac9a5702345e768680334141fdedd5ba41f1 100644 (file)
@@ -188,6 +188,7 @@ struct _ThemeImage
 
 G_GNUC_INTERNAL ThemePixbuf *theme_pixbuf_new          (void);
 G_GNUC_INTERNAL void         theme_pixbuf_destroy      (ThemePixbuf  *theme_pb);
+G_GNUC_INTERNAL void         theme_clear_pixbuf        (ThemePixbuf **theme_pb);
 G_GNUC_INTERNAL void         theme_pixbuf_set_filename (ThemePixbuf  *theme_pb,
                                        const char   *filename);
 G_GNUC_INTERNAL GdkPixbuf *  theme_pixbuf_get_pixbuf   (ThemePixbuf  *theme_pb);